package com.example.demo.repository;

import com.example.demo.entity.SchoolGrade;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.data.repository.query.Param;
import reactor.core.publisher.Mono;

public interface SchooGradeRepository extends R2dbcRepository<SchoolGrade, Long> {

    @Modifying
    @Query( "insert into t_grade(id,name) VALUES (:#{#grade.id},:#{#grade.name})"+
            "on conflict (id) do update SET " +
            "name = CASE WHEN :#{#grade.name} IS NULL THEN t_grade.name ELSE :#{#grade.name} END " )
    Mono<SchoolGrade> insertOrUpdateGrade(@Param("grade") SchoolGrade grade);

}

